<?php

if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER ['HTTP_X_REQUESTED_WITH']  == 'XMLHttpRequest') {
	require('../../../../wp-config.php');
	auth_redirect();
	
	global $wpdb, $canvas;
	
	if(isset($_GET["delete"])) canvas_delete_block($_GET["delete"]);
	if(isset($_GET["duplicate"])) canvas_create_management_block(canvas_duplicate_block($_GET["duplicate"]),' style="display: none"');
	
	if($_GET["update"] == 'all') {
		$blocks = $wpdb->get_results("SELECT * FROM ".$canvas->main." WHERE theme = '".get_option('template')."' ORDER BY block_name");
		$delete_button = get_option('canvas_allow_deletion');
		foreach($blocks as $block) {
			canvas_create_management_block($block,'',$delete_button);
		}
	}
	if(isset($_POST["rename"]) && $_POST["rename"] == 'true') {
		$block_name = urldecode($_POST["value"]);
		$block_id = str_replace('title_','',$_POST["id"]);
		$wpdb->query("UPDATE ".$canvas->main." SET block_name='$block_name' WHERE block_id='$block_id'");
		echo $block_name;
	}
}
?>